1. Field of the Invention:
The present invention is directed to data processing systems. More specifically, the present invention is directed to a method and apparatus for generating multiple analog signals using a single microcontroller output pin.
2. Description of the Related Art:
A common task for microcontrollers is the generation of analog voltage outputs. Such outputs may be used as reference voltages to control other circuits or may be re-powered and used to control motors, servos, or other mechanical devices.
One of the most common methods for microcontroller generation of analog voltage is pulse width modulation (PWM). This method consists of driving an output pin on the microcontroller alternately high and then low. A resistor/capacitor (R/C) circuit connected to the output pins integrates the pulse train by smoothing the pulse train to a relatively stable voltage. The ratio of high cycle time to total cycle time defines the output voltage by the follow formula:V(out)=[[[V(output high)−V(output low)]*T(high cycle)]/T(total cycle)]+V(output low).
FIG. 1 depicts three examples of waveforms that are each a single PWM waveform in accordance with the prior art. The sample waveforms represent approximately 1.35 Volts, 4.34 Volts, and 2.50 Volts, respectively, assuming an output high voltage of 4.8 Volts and output low voltage of 0.2 Volts for a typical 5 Volt CMOS microcontroller.
Each waveform can be used to generate only one analog voltage. Thus, each waveform includes only one signal that has uniform pulses throughout the entire waveform.
FIG. 2 illustrates a portion of a microcontroller and an external circuit for integrating a PWM that is output from the microcontroller to produce an analog signal in accordance with the prior art. A portion of a microcontroller 200 is depicted. Microcontroller 200 drives output pin 202 alternatively high and low using transistors 204 and 206. As described above, a waveform, such as one of the waveforms depicted in FIG. 1, is output from pin 202. Circuit 208 includes a resistor 210 and a capacitor 212. Circuit 208 integrates the waveform received from pin 202 in order to produce a relatively stable analog voltage signal at output 214.
Instead of circuit 208, other, more accurate, forms of integration, such as operational amplifiers, could be used, as described in the prior art.
Microcontroller 200 can output only one of the waveforms of FIG. 1 using one of the pins of microcontroller 200. If all three waveforms depicted in FIG. 1 are needed, at least three different output pins of the microcontroller must be used. A separate microcontroller pin must be used for each analog signal that is needed. Thus, a dedicated microcontroller pin is required in order to produce each PWM waveform.
The usual method for generating multiple analog voltage outputs involves using a monolithic digital-to-analog (D/A) device. These are available in parallel input configurations ideal for microcontroller use but require up to nine pins for interfacing. Serial bus interface D/A devices are also available. While they can be interfaced with as few as two pins, these have the disadvantage of requiring the microcontroller to generate the appropriate bus interface signals and sometimes complex communications protocols.
Therefore, a need exists for a method and apparatus for generating a plurality of separate digital PWM signals that can each be used to generate a different analog signal by a microcontroller using a single pin and minimal programming resulting in the generation of multiple separate analog signals using the same single pin of the microcontroller.